package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.SystemDictionary;
import cn.wolfcode.rbac.domain.SystemDictionaryItem;
import cn.wolfcode.rbac.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.rbac.mapper.SystemDictionaryMapper;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.query.SystemDionaryItemQuery;
import cn.wolfcode.rbac.service.ISystemDictionaryItemService;
import cn.wolfcode.rbac.service.ISystemDictionaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {
    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;

    @Override
    public void saveOrUpdate(SystemDictionaryItem entity) {
        if(entity.getId() == null){
            //进行插入操作
            this.systemDictionaryItemMapper.insert(entity);
        }else{
            //进行修改操作
            this.systemDictionaryItemMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    @Transactional(readOnly = true)
    public SystemDictionaryItem get(Long id) {
        return this.systemDictionaryItemMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<SystemDictionaryItem> list() {
        return this.systemDictionaryItemMapper.selectAll();
    }
    @Override
    @Transactional(readOnly = true)
    public PageInfo query(SystemDionaryItemQuery paramQueryObject) {
     PageHelper.startPage(paramQueryObject.getCurrentPage(), paramQueryObject.getPageSize());
        List<SystemDictionaryItem> list = this.systemDictionaryItemMapper.selectForList(paramQueryObject);
        return new PageInfo(list);
    }

    @Override
    public void delete(Long id) {
        this.systemDictionaryItemMapper.delete(id);
    }

    @Override
    public List<SystemDictionaryItem> selectBysySystemDictionaryId() {
        return this.systemDictionaryItemMapper.selectBysySystemDictionaryId();
    }

    @Override
    public List<SystemDictionaryItem> selectSourcetBysySystemDictionaryId() {
        return this.systemDictionaryItemMapper.selectSourcetBysySystemDictionaryId();
    }

    @Override
    public List<SystemDictionaryItem> selectMode() {
        return this.systemDictionaryItemMapper.selectMode();
    }

}

